class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        ListNode* head = new ListNode(0);
        ListNode* tail = head;
        int ret = 0; // 进位
        while (l1 || l2 || ret) {
            if (l1)
                ret += l1->val;
            if (l2)
                ret += l2->val;
            ListNode* cur = new ListNode(ret%10);
            ret /= 10;
            tail->next = cur;
            tail = tail->next;
            if (l1) {
                l1 = l1->next;
            }
            if (l2) {
                l2 = l2->next;
            }
        }
        tail = head->next;
        delete head;
        return tail;
    }
};